<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数节流（时间戳）</title>
</head>
<body>
    <input type="text" id="ipt">
    <script>
        let ipt = document.getElementById("ipt");
        // function throttling(func,time){
        //     let startTime = 0;
        //     return function(){
        //         let currentTime = new Date().getTime();
        //         if(currentTime - startTime > time){
        //             func();
        //             startTime = new Date().getTime();
        //         }
        //     }
        // }
        // ipt.onkeyup = throttling(function(){
        //     console.log(ipt.value);
        // },500);
        // 函数节流（时间间隔）
        let timeoutId = 0;
        ipt.onkeyup = function(){
            if(timeoutId){
                return;
            }
            timeoutId = setTimeout(function(){
                console.log(ipt.value);
                timeoutId = 0;
            },500);
        }
    </script>
</body>
</html>